package com.ambitor.grass.sql.statement;

import java.sql.Connection;

import com.ambitor.grass.util.data.IData;
import com.ambitor.grass.util.data.IDataset;

public class BatchPreStatementImpl extends PreStatementImpl implements
		BatchOperation {

	private IDataset params;

	public BatchPreStatementImpl(Connection conn, String sqlstr, IDataset params)
			throws Exception {
		super(conn, sqlstr);
		this.params = params;
	}

	public int[] executeBatch() throws Exception {
		if (this.params.count() == 0)
			return new int[0];

		for (int i = 0; i < this.params.count(); ++i) {
			setParameters((IData) this.params.get(i));
			this.getStatement().addBatch();
		}

		int[] result = this.getStatement().executeBatch();
		this.close();   //
		return result;
	}

}
